﻿Public Class SubFactura

    Dim concepto As String
    Dim subtotal As Double
    Dim IVA As Double
    Dim regreso As Boolean = False

    Public Function mostrar(ByVal titulo As String, ByRef vConcepto As String, ByRef vSubTotal As Double, ByRef vIva As Double) As Boolean
        Me.Text = titulo
        txtConcepto.Text = ""
        txtSubTotal.Text = ""
        txtIVA.Text = Format(vIva, "#0%")
        txtConcepto.Focus()
        Me.ShowDialog()
        vConcepto = concepto
        vSubTotal = subtotal
        vIva = IVA
        Return regreso
    End Function

    Private Sub SubFactura_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtConcepto.Focus()
        regreso = False
    End Sub

    Private Sub txtConcepto_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtConcepto.KeyDown
        If e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Return Then
            concepto = txtConcepto.Text
            txtSubTotal.Focus()
        End If
    End Sub

    Private Sub txtSubTotal_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtSubTotal.KeyDown
        If e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Return Then
            subtotal = Val(txtSubTotal.Text)
            txtSubTotal.Text = Format(Val(txtSubTotal.Text), "$ ###,###,##0.00")
            txtIVA.Focus()
        End If
    End Sub

    Private Sub Montos_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSubTotal.KeyPress
        If Char.IsDigit(e.KeyChar) Or e.KeyChar = "-"c Or e.KeyChar = ""c Or e.KeyChar = "."c Then
            e.Handled = False
        Else
            e.Handled = True
        End If
    End Sub

    Private Sub txtIVA_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtIVA.KeyDown
        If e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Return Then
            IVA = Val(txtIVA.Text) / 100
            txtIVA.Text = Format(IVA, "#0%")
            If txtSubTotal.Text.Trim.Length > 0 And txtConcepto.Text.Trim.Length > 0 And txtIVA.Text.Trim.Length > 0 Then
                btnAgregar.Visible = True
                btnAgregar.Focus()
            Else
                txtConcepto.Focus()
            End If
        End If
    End Sub

    Private Sub txtIVA_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtIVA.KeyPress
        If Char.IsDigit(e.KeyChar) Then
            e.Handled = False
        Else
            e.Handled = True
        End If
    End Sub

    Private Sub btnAgregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAgregar.Click
        Me.Close()
        regreso = True
    End Sub
End Class